﻿/**
 * ZoomBlurFilter
 * 
 * @author		Allen Chou
 * @version		1.0.2 (last update: Nov 24 2008)
 * @link        http://cjcat.blogspot.com
 * @link		http://cjcat2266.deviantart.com
 */
 
package idv.cjcat.filters {
	import flash.display.Shader;
	import flash.filters.ShaderFilter;
	import flash.utils.ByteArray;
	
	import idv.cjcat.utils.ByteArrayCodec;

	/**
	 * The original ZoomBlur Pixel Bender filter is created by Ryan Phelan.
	 */
	public class ZoomBlurFilter extends ShaderFilter {
		
		public function ZoomBlurFilter(amount:Number = 2, centerX:Number = 0, centerY:Number = 0, extensions:Number = 0) {
			if (pbjByteArray == null) pbjByteArray = ByteArrayCodec.decode(pbjString);
			
			this.shader = new Shader(pbjByteArray);
			this.amount = amount;
			this.centerX = centerX;
			this.centerY = centerY;
		}
		
		
		/**
		 * The amount of zoom blur.
		 */
		public function get amount():Number { return this.shader.data.amount.value[0]; }
		public function set amount(value:Number):void { this.shader.data.amount.value[0] = value; }
		
		/**
		 * The x coordinate of the center of zoom blur.
		 */
		public function get centerX():Number { return this.shader.data.center.value[0]; }
		public function set centerX(value:Number):void {
			this.shader.data.center.value[0] = value;
		}
		
		/**
		 * The y coordinate of the center of zoom blur.
		 */
		public function get centerY():Number { return this.shader.data.center.value[1]; }
		public function set centerY(value:Number):void {
			this.shader.data.center.value[1] = value;
		}
		
		/**
		 * The amount of filter border extensions.
		 */
		public function get extensions():Number { return this.topExtension; }
		public function set extensions(value:Number):void {
			this.topExtension = this.bottomExtension = this.leftExtension = this.rightExtension = value;
		}
		
		private static const pbjString:String = "2581808080248880DAEFEFEDC2ECF5F2208CEEE1EDE5F3F0E1E3E580E3EFEDAEF2F0E8E5ECE1EE80208CF6E5EEE4EFF280D2F9E1EEA0D0E8E5ECE1EE802088F6E5F2F3E9EFEE808180208CE4E5F3E3F2E9F0F4E9EFEE80C1A0F3E9EDF0ECE5A0E9EDF0ECE5EDE5EEF4E1F4E9EFEEA0EFE6A0FAEFEFEDA0E2ECF5F2ACA0F5F3E9EEE7A0B1B5A0ECE5F6E5ECF3A0EFE6A0E2ECF5F2AE8021818280808CDFCFF5F4C3EFEFF2E480218182808083E3E5EEF4E5F2802282EDE9EED6E1ECF5E58045808080458080802282EDE1F8D6E1ECF5E580C5808080C58080802282E4E5E6E1F5ECF4D6E1ECF5E5808080808080808080218181818088E1EDEFF5EEF4802281EDE9EED6E1ECF5E580808080802281EDE1F8D6E1ECF5E580BF8080802281E4E5E6E1F5ECF4D6E1ECF5E580BDCC4C4D238084F3F2E38021828482808FE4F3F4809D8180E180809080828180E180803080B282800080808080B28280C080808080B28280A080808080B282809080808080B2818090BF0080809D8380418180E08083838041818070809D8380B183809080818380B180803080B0848071838030808182807384809B80B2838000BF008080B28380C0BD12C9A59D8380A081808080838380A08380C0809D8380C083808080818380C0838000809D8180908380C0809D8380418180E08083838041818070809D8380B183809080818380B180803080B0848071838030808182807384809B80B2838000BF008080B28380C0BE92C9A59D8380A081808080838380A08380C0809D8380C083808080818380C0838000809D8180908380C0809D8380418180E08083838041818070809D8380B183809080818380B180803080B0848071838030808182807384809B80B2838000BF008080B28380C0BEDBED379D8380A081808080838380A08380C0809D8380C083808080818380C0838000809D8180908380C0809D8380418180E08083838041818070809D8380B183809080818380B180803080B0848071838030808182807384809B80B2838000BF008080B28380C0BE12C9A59D8380A081808080838380A08380C0809D8380C083808080818380C0838000809D8180908380C0809D8380418180E08083838041818070809D8380B183809080818380B180803080B0848071838030808182807384809B80B2838000BF008080B28380C0BE365BEE9D8380A081808080838380A08380C0809D8380C083808080818380C0838000809D8180908380C0809D8380418180E08083838041818070809D8380B183809080818380B180803080B0848071838030808182807384809B80B2838000BF008080B28380C0BE5BED379D8380A081808080838380A08380C0809D8380C083808080818380C0838000809D8180908380C0809D8380418180E08083838041818070809D8380B183809080818380B180803080B0848071838030808182807384809B80B2838000BF008080B28380C0BF8080809D8380A081808080838380A08380C0809D8380C083808080818380C0838000809D8180908380C0809D8380418180E08083838041818070809D8380B183809080818380B180803080B0848071838030808182807384809B80B2838000BF008080B28380C0BF92C9A59D8380A081808080838380A08380C0809D8380C083808080818380C0838000809D8180908380C0809D8380418180E08083838041818070809D8380B183809080818380B180803080B0848071838030808182807384809B80B2838000BF008080B28380C0BFA412C99D8380A081808080838380A08380C0809D8380C083808080818380C0838000809D8180908380C0809D8380418180E08083838041818070809D8380B183809080818380B180803080B0848071838030808182807384809B80B2838000BF008080B28380C0BFB65BEE9D8380A081808080838380A08380C0809D8380C083808080818380C0838000809D8180908380C0809D8380418180E08083838041818070809D8380B183809080818380B180803080B0848071838030808182807384809B80B2838000BF008080B28380C0BFC9A4129D8380A081808080838380A08380C0809D8380C083808080818380C0838000809D8180908380C0809D8380418180E08083838041818070809D8380B183809080818380B180803080B0848071838030808182807384809B80B2838000BF008080B28380C0BFDBED379D8380A081808080838380A08380C0809D8380C083808080818380C0838000809D8180908380C0809D8380418180E08083838041818070809D8380B183809080818380B180803080B0848071838030808182807384809B80B2838000BF008080B28380C0BFED365B9D8380A081808080838380A08380C0809D8380C083808080818380C0838000809D8180908380C0809D8380418180E08083838041818070809D8380B183809080818380B180803080B0848071838030808182807384809B80B2838000BF008080B28380C0BF0080809D8380A081808080838380A08380C0809D8380C083808080818380C0838000809D8180908380C0809D8380418180E08083838041818070809D8380B183809080818380B180803080B0848071838030808182807384809B80B2838000C1F0808084848073838080808382807384809B80";
		private static var pbjByteArray:ByteArray = null;
	}
}